<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>


<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<meta name="theme-color" content="#f8f5ec" />
<meta name="msapplication-navbutton-color" content="#f8f5ec">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">



  <meta name="description" content="Eclipse中Git的使用"/>




  <meta name="keywords" content="git的使用, 金色的大海" />










  <link rel="alternate" href="/blog/default" title="金色的大海">




  <link rel="shortcut icon" type="image/x-icon" href="/blog/favicon.ico?v=2.9.0" />



<link rel="canonical" href="http://jy4416.gitee.io/blog/2020/04/15/eclipse-git/"/>



  <link rel="stylesheet" type="text/css" href="/blog/lib/fancybox/jquery.fancybox.css" />




  <link rel="stylesheet" type="text/css" href="/blog/lib/nprogress/nprogress.min.css" />



<link rel="stylesheet" type="text/css" href="/blog/css/style.css?v=2.9.0" />



  



  <script id="baidu_push">
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>








<script>
  window.config = {"title":"金色的大海","subtitle":"","description":"","author":"jy","language":"zh-cn","timezone":"","url":"http://jy4416.gitee.io/blog","root":"/blog/","permalink":":year/:month/:day/:title/","permalink_defaults":null,"pretty_urls":{"trailing_index":true,"trailing_html":true},"source_dir":"source","public_dir":"public","tag_dir":"tags","archive_dir":"archives","category_dir":"categories","code_dir":"downloads/code","i18n_dir":":lang","skip_render":null,"new_post_name":":title.md","default_layout":"post","titlecase":false,"external_link":{"enable":true,"field":"site","exclude":""},"filename_case":0,"render_drafts":false,"post_asset_folder":true,"relative_link":false,"future":true,"highlight":{"enable":true,"auto_detect":false,"line_number":true,"tab_replace":"","wrap":true,"hljs":false},"default_category":"uncategorized","category_map":null,"tag_map":null,"date_format":"YYYY-MM-DD","time_format":"HH:mm:ss","use_date_for_updated":false,"per_page":10,"pagination_dir":"page","theme":"hexo-theme-even","server":{"port":4000,"log":false,"compress":false,"header":true,"cache":false},"deploy":{"type":"git","repo":"https://gitee.com/j4416/blog.git","branch":"master"},"ignore":null,"meta_generator":true,"keywords":null,"index_generator":{"per_page":10,"order_by":"-date","path":""},"include":null,"exclude":null,"category_generator":{"per_page":10},"archive_generator":{"per_page":10,"yearly":true,"monthly":true,"daily":false},"marked":{"gfm":true,"pedantic":false,"breaks":true,"smartLists":true,"smartypants":true,"modifyAnchors":"","autolink":true,"sanitizeUrl":false,"headerIds":true},"tag_generator":{"per_page":10},"since":2020,"favicon":"/favicon.ico","rss":"default","menu":{"Home":"/","Archives":"/archives/","Tags":"/tags","Categories":"/categories","About":"/about"},"color":"Default","toc":true,"fancybox":true,"pjax":true,"copyright":{"enable":true,"license":"<a rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc/4.0/\" target=\"_blank\">知识共享署名-非商业性使用 4.0 国际许可协议</a>"},"reward":{"enable":false,"qrCode":{"wechat":null,"alipay":null}},"social":{"email":"jy4416@aliyun.com","stack-overflow":null,"twitter":null,"facebook":null,"linkedin":null,"google":null,"github":"https://github.com/jy4416","weibo":null,"zhihu":null,"douban":null,"pocket":null,"tumblr":null,"instagram":null},"leancloud":{"app_id":null,"app_key":null},"baidu_analytics":null,"baidu_verification":null,"google_analytics":null,"google_verification":null,"disqus_shortname":null,"changyan":{"appid":null,"appkey":null},"livere_datauid":null,"version":"2.9.0"};
</script>

    <title> Eclipse中Git的使用 - 金色的大海 </title>
  <meta name="generator" content="Hexo 4.2.0"></head>

  <body><div id="mobile-navbar" class="mobile-navbar">
  <div class="mobile-header-logo">
    <a href="/blog/." class="logo">金色的大海</a>
  </div>
  <div class="mobile-navbar-icon">
    <span></span>
    <span></span>
    <span></span>
  </div>
</div>

<nav id="mobile-menu" class="mobile-menu slideout-menu">
  <ul class="mobile-menu-list">
    
      <a href="/blog/">
        <li class="mobile-menu-item">
          
          
            首页
          
        </li>
      </a>
    
      <a href="/blog/archives/">
        <li class="mobile-menu-item">
          
          
            归档
          
        </li>
      </a>
    
      <a href="/blog/tags">
        <li class="mobile-menu-item">
          
          
            标签
          
        </li>
      </a>
    
      <a href="/blog/categories">
        <li class="mobile-menu-item">
          
          
            分类
          
        </li>
      </a>
    
      <a href="/blog/about">
        <li class="mobile-menu-item">
          
          
            关于
          
        </li>
      </a>
    
  </ul>
</nav>

    <div class="container" id="mobile-panel">
      <header id="header" class="header"><div class="logo-wrapper">
  <a href="/blog/." class="logo">金色的大海</a>
</div>

<nav class="site-navbar">
  
    <ul id="menu" class="menu">
      
        <li class="menu-item">
          <a class="menu-item-link" href="/blog/">
            
            
              首页
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/blog/archives/">
            
            
              归档
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/blog/tags">
            
            
              标签
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/blog/categories">
            
            
              分类
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/blog/about">
            
            
              关于
            
          </a>
        </li>
      
    </ul>
  
</nav>

      </header>

      <main id="main" class="main">
        <div class="content-wrapper">
          <div id="content" class="content">
            
  
  <article class="post">
    <header class="post-header">
      <h1 class="post-title">
        
          Eclipse中Git的使用
        
      </h1>

      <div class="post-meta">
        <span class="post-time">
          2020-04-15
        </span>
        
          <div class="post-category">
            
              <a href="/blog/categories/Git/">Git</a>
            
          </div>
        
        
      </div>
    </header>

    
    
  <div class="post-toc" id="post-toc">
    <h2 class="post-toc-title">文章目录</h2>
    <div class="post-toc-content">
      <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#一、准备"><span class="toc-text">一、准备</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#二、从远程Git库中克隆代码"><span class="toc-text">二、从远程Git库中克隆代码</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#三、Git的使用"><span class="toc-text">三、Git的使用</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#Git提交"><span class="toc-text">Git提交</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Git拉取"><span class="toc-text">Git拉取</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#四、Git冲突解决"><span class="toc-text">四、Git冲突解决</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#拉取代码时冲突"><span class="toc-text">拉取代码时冲突</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-提交本地"><span class="toc-text">1.提交本地</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-拉取代码"><span class="toc-text">2.拉取代码</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-合并代码"><span class="toc-text">3.合并代码</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#手动修改"><span class="toc-text">手动修改</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#或使用合并工具"><span class="toc-text">或使用合并工具</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-重新提交代码"><span class="toc-text">4.重新提交代码</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#提交代码时冲突"><span class="toc-text">提交代码时冲突</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-提交代码"><span class="toc-text">1.提交代码</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-拉取代码-1"><span class="toc-text">2.拉取代码</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-合并代码-1"><span class="toc-text">3.合并代码</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#手动修改-1"><span class="toc-text">手动修改</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#或使用合并工具-1"><span class="toc-text">或使用合并工具</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-重新提交代码-1"><span class="toc-text">4.重新提交代码</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#五、本地推送代码到远程Git库"><span class="toc-text">五、本地推送代码到远程Git库</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#创建本地Git版本库"><span class="toc-text">创建本地Git版本库</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#新建项目"><span class="toc-text">新建项目</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#项目添加到Git库"><span class="toc-text">项目添加到Git库</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#选择Team"><span class="toc-text">选择Team</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#选择Git"><span class="toc-text">选择Git</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#创建本地Git库"><span class="toc-text">创建本地Git库</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#提交本地库"><span class="toc-text">提交本地库</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#推送到远程库"><span class="toc-text">推送到远程库</span></a></li></ol></li></ol></li></ol></li></ol>
    </div>
  </div>



    <div class="post-content">
      
        <h1 id="一、准备"><a href="#一、准备" class="headerlink" title="一、准备"></a>一、准备</h1><p>选择Eclipse4.0以上的版本都有git插件。</p>
<p>在【Preferences(首选项)】—【Team】—Git查看</p>
<img src="http://i1.fuimg.com/709257/44c8725596a75184.png">

<h1 id="二、从远程Git库中克隆代码"><a href="#二、从远程Git库中克隆代码" class="headerlink" title="二、从远程Git库中克隆代码"></a>二、从远程Git库中克隆代码</h1><p>从远程Git库中clone代码到本地</p>
<a id="more"></a>

<p>在Eclipse中选择【File】—【import..】</p>
<img src="http://i1.fuimg.com/709257/4bbdb3cddc4a3a49.png" alt="Markdown">

<img src="http://i1.fuimg.com/709257/3b6fbf47655e1c5f.png" alt="Markdown">

<img src="http://i1.fuimg.com/709257/5f8bae7b5c60a022.png" alt="Markdown">

<img src="http://i2.tiimg.com/709257/d3a2a8d1e928b59b.png" alt="Markdown">

<p><img src="http://i2.tiimg.com/709257/51363fe30024ea57.png" alt="Markdown"></p>
<p><img src="http://i2.tiimg.com/709257/f93645b02ac77e3c.png" alt="Markdown"></p>
<p><img src="http://i2.tiimg.com/709257/c80fdb87bd2e4c4c.png" alt="Markdown"></p>
<h1 id="三、Git的使用"><a href="#三、Git的使用" class="headerlink" title="三、Git的使用"></a>三、Git的使用</h1><p>首先通过add将需要管理的代码文件添加到Git库中，然后通过commit提交到本地库，再通过push推送到远程。</p>
<p>!<img src="http://i1.fuimg.com/709257/d39d87cb93b0f45d.png" alt="Markdown"></p>
<h2 id="Git提交"><a href="#Git提交" class="headerlink" title="Git提交"></a>Git提交</h2><p>commit提交代码到本地Git库，push推送到远程服务器</p>
<p><img src="http://i1.fuimg.com/709257/927b2dceabe8b3d3.png" alt="Markdown"></p>
<h2 id="Git拉取"><a href="#Git拉取" class="headerlink" title="Git拉取"></a>Git拉取</h2><p>pull从远程服务器中拉取代码到本地</p>
<p><img src="http://i1.fuimg.com/709257/c27c5bdd9d48c298.png" alt="Markdown"></p>
<h1 id="四、Git冲突解决"><a href="#四、Git冲突解决" class="headerlink" title="四、Git冲突解决"></a>四、Git冲突解决</h1><p>如果有2人以上修改同一个文件，在推送或下拉时会提示代码冲突。</p>
<h2 id="拉取代码时冲突"><a href="#拉取代码时冲突" class="headerlink" title="拉取代码时冲突"></a>拉取代码时冲突</h2><p>拉取（pull)代码时产生冲突</p>
<p><img src="http://i2.tiimg.com/709257/f825f54b65d3fa9e.png" alt="Markdown"></p>
<h3 id="1-提交本地"><a href="#1-提交本地" class="headerlink" title="1.提交本地"></a>1.提交本地</h3><p>首先将冲突的文件提交到本地（commit)</p>
<p><img src="http://i1.fuimg.com/709257/35abeb0e0ee0b313.png" alt="Markdown"></p>
<h3 id="2-拉取代码"><a href="#2-拉取代码" class="headerlink" title="2.拉取代码"></a>2.拉取代码</h3><p>重新拉取远程的代码（pull)</p>
<h3 id="3-合并代码"><a href="#3-合并代码" class="headerlink" title="3.合并代码"></a>3.合并代码</h3><p>拉取后会出现代码合并界面，在此界面可以保留本地代码，或保留远程代码，或者两个合并。</p>
<h5 id="手动修改"><a href="#手动修改" class="headerlink" title="手动修改"></a>手动修改</h5><p><img src="http://i1.fuimg.com/709257/8308880f8392a03e.png" alt="Markdown"></p>
<h5 id="或使用合并工具"><a href="#或使用合并工具" class="headerlink" title="或使用合并工具"></a>或使用合并工具</h5><p><img src="http://i2.tiimg.com/709257/10e8879cf50e7ed7.png" alt="Markdown"></p>
<p><img src="http://i2.tiimg.com/709257/accfaea4f90f72a6.png" alt="Markdown"></p>
<h3 id="4-重新提交代码"><a href="#4-重新提交代码" class="headerlink" title="4.重新提交代码"></a>4.重新提交代码</h3><p>解决冲突后一定要保存冲突文件，重新提交。</p>
<p><img src="http://i1.fuimg.com/709257/1526ad8f301bf76b.png" alt="Markdown"></p>
<h2 id="提交代码时冲突"><a href="#提交代码时冲突" class="headerlink" title="提交代码时冲突"></a>提交代码时冲突</h2><h3 id="1-提交代码"><a href="#1-提交代码" class="headerlink" title="1.提交代码"></a>1.提交代码</h3><p>提交(push)代码产生冲突时会弹出错误提示界面。</p>
<p><img src="http://i1.fuimg.com/709257/631397568e4c1fc5.png" alt="Markdown"></p>
<h3 id="2-拉取代码-1"><a href="#2-拉取代码-1" class="headerlink" title="2.拉取代码"></a>2.拉取代码</h3><p>提交冲突后，拉取远程的代码（pull)</p>
<h3 id="3-合并代码-1"><a href="#3-合并代码-1" class="headerlink" title="3.合并代码"></a>3.合并代码</h3><p>拉取后会出现代码合并界面，在此界面可以保留本地代码，或保留远程代码，或者两个合并。</p>
<h5 id="手动修改-1"><a href="#手动修改-1" class="headerlink" title="手动修改"></a>手动修改</h5><p><img src="http://i1.fuimg.com/709257/8308880f8392a03e.png" alt="Markdown"></p>
<h5 id="或使用合并工具-1"><a href="#或使用合并工具-1" class="headerlink" title="或使用合并工具"></a>或使用合并工具</h5><p><img src="http://i2.tiimg.com/709257/10e8879cf50e7ed7.png" alt="Markdown"></p>
<p><img src="http://i2.tiimg.com/709257/accfaea4f90f72a6.png" alt="Markdown"></p>
<h3 id="4-重新提交代码-1"><a href="#4-重新提交代码-1" class="headerlink" title="4.重新提交代码"></a>4.重新提交代码</h3><p>解决冲突后一定要保存冲突文件，重新提交。</p>
<p><img src="http://i1.fuimg.com/709257/1526ad8f301bf76b.png" alt="Markdown"></p>
<h1 id="五、本地推送代码到远程Git库"><a href="#五、本地推送代码到远程Git库" class="headerlink" title="五、本地推送代码到远程Git库"></a>五、本地推送代码到远程Git库</h1><h2 id="创建本地Git版本库"><a href="#创建本地Git版本库" class="headerlink" title="创建本地Git版本库"></a>创建本地Git版本库</h2><h3 id="新建项目"><a href="#新建项目" class="headerlink" title="新建项目"></a>新建项目</h3><p>新建一个本地Java项目</p>
<h3 id="项目添加到Git库"><a href="#项目添加到Git库" class="headerlink" title="项目添加到Git库"></a>项目添加到Git库</h3><h4 id="选择Team"><a href="#选择Team" class="headerlink" title="选择Team"></a>选择Team</h4><p><img src="http://i1.fuimg.com/709257/48c33f6181eb22b1.png" alt></p>
<h4 id="选择Git"><a href="#选择Git" class="headerlink" title="选择Git"></a>选择Git</h4><p><img src="http://i1.fuimg.com/709257/84c6b11969540324.png" alt></p>
<h4 id="创建本地Git库"><a href="#创建本地Git库" class="headerlink" title="创建本地Git库"></a>创建本地Git库</h4><p><img src="http://i1.fuimg.com/709257/65dcab02ac7cd5cf.png" alt></p>
<p><img src="http://i1.fuimg.com/709257/c9527151004a3845.png" alt="Markdown"></p>
<h4 id="提交本地库"><a href="#提交本地库" class="headerlink" title="提交本地库"></a>提交本地库</h4><p><img src="http://i1.fuimg.com/709257/6f75005d61602782.png" alt="Markdown"></p>
<p><img src="http://i1.fuimg.com/709257/eb6e8dd0e75ba2fb.jpg" alt="Markdown"></p>
<h4 id="推送到远程库"><a href="#推送到远程库" class="headerlink" title="推送到远程库"></a>推送到远程库</h4><p><img src="http://i1.fuimg.com/709257/6daf6b2fdd80d2cb.jpg" alt="Markdown"></p>

      
    </div>

    
      
      

  <div class="post-copyright">
    <p class="copyright-item">
      <span>原文作者: </span>
      <a href="http://jy4416.gitee.io/blog">jy</a>
    </p>
    <p class="copyright-item">
      <span>原文链接: </span>
      <a href="http://jy4416.gitee.io/blog/2020/04/15/eclipse-git/">http://jy4416.gitee.io/blog/2020/04/15/eclipse-git/</a>
    </p>
    <p class="copyright-item">
      <span>许可协议: </span>
      
      <a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/" target="_blank">知识共享署名-非商业性使用 4.0 国际许可协议</a>
    </p>
  </div>



      
      
    

    
      <footer class="post-footer">
        
          <div class="post-tags">
            
              <a href="/blog/tags/git%E7%9A%84%E4%BD%BF%E7%94%A8/">git的使用</a>
            
          </div>
        
        
        
  <nav class="post-nav">
    
    
      <a class="next" href="/blog/2020/04/15/asgit/">
        <span class="next-text nav-default">Android Studio Git使用</span>
        <span class="prev-text nav-mobile">下一篇</span>
        <i class="iconfont icon-right"></i>
      </a>
    
  </nav>

      </footer>
    

  </article>


          </div>
          
  <div class="comments" id="comments">
    
  </div>


        </div>
      </main>

      <footer id="footer" class="footer">

  <div class="social-links">
    
      
        
          <a href="mailto:jy4416@aliyun.com" class="iconfont icon-email" title="email"></a>
        
      
    
      
    
      
    
      
    
      
    
      
    
      
        
          <a href="https://github.com/jy4416" target="_blank" rel="noopener" class="iconfont icon-github" title="github"></a>
        
      
    
      
    
      
    
      
    
      
    
      
    
      
    
    
    
      
      <a href="/blog/atom.xml" class="iconfont icon-rss" title="rss"></a>
    
  </div>


<div class="copyright">
  <span class="power-by">
    由 <a class="hexo-link" href="https://hexo.io/" target="_blank" rel="noopener">Hexo</a> 强力驱动
  </span>
  <span class="division">|</span>
  <span class="theme-info">
    主题 - 
    <a class="theme-link" href="https://github.com/ahonn/hexo-theme-even" target="_blank" rel="noopener">Even</a>
  </span>

  <span class="copyright-year">
    
    &copy; 
    
    2020

    <span class="heart">
      <i class="iconfont icon-heart"></i>
    </span>
    <span class="author">jy</span>
  </span>
</div>

      </footer>

      <div class="back-to-top" id="back-to-top">
        <i class="iconfont icon-up"></i>
      </div>
    </div>

    
  
  

  



    
  



  
  





  
    <script type="text/javascript" src="/blog/lib/jquery/jquery.min.js"></script>
  

  
    <script type="text/javascript" src="/blog/lib/slideout/slideout.js"></script>
  

  
    <script type="text/javascript" src="/blog/lib/fancybox/jquery.fancybox.pack.js"></script>
  

  
    <script type="text/javascript" src="/blog/lib/pjax/jquery.pjax.min.js"></script>
  

  
    <script type="text/javascript" src="/blog/lib/nprogress/nprogress.min.js"></script>
  


    <script type="text/javascript" src="/blog/js/src/even.js?v=2.9.0"></script>

  </body>
</html>
